﻿//------------------------------------------------------------
// Author: 烟雨迷离半世殇
// Mail: 1778139321@qq.com
// Data: 2020年1月5日 19:47:39
//------------------------------------------------------------

using System;
using System.Text;

namespace NKG_MVVM_UI
{
    public class Test01Model : AModelBase<Test01AViewModel>
    {
        private string m_Text;
        private int m_Image;

        public string Text
        {
            get { return this.m_Text; }
            set { m_Test01ViewModel.Text.Value = value; }
        }

        public int Image
        {
            get { return this.m_Image; }
            set { m_Test01ViewModel.Image.Value = value; }
        }

        private Test01AViewModel m_Test01ViewModel;

        public override void Init(Test01AViewModel viewModel)
        {
            this.m_Test01ViewModel = viewModel;

            this.m_Test01ViewModel.Test01ModelRef = this;
            this.m_Test01ViewModel.Text.OnValueChanged += (oldValue, newValue) => { this.m_Text = newValue; };
            this.m_Test01ViewModel.Image.OnValueChanged += (oldValue, newValue) => { this.m_Image = newValue; };
        }

        public void ChangeModelContent()
        {
            Console.WriteLine("----------------------------------");
            Console.WriteLine("模拟游戏逻辑更改Model");
            this.Text = "Hello";
            this.Image = 10000;
            Console.WriteLine("----------------------------------");
        }

        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();
            sb.Append($"Test01Model：Text:{Text},Image：{Image}");
            return sb.ToString();
        }
    }
}